﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;




using gestionClinica.conexion;
using gestionClinica.Gestion_DB;


namespace GestionClinicaWPF
{
    /// <summary>
    /// Lógica de interacción para MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private gestion gest = new gestion();
       
       

        public MainWindow()
        {
            InitializeComponent();
           

        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            grillaDoctores.ItemsSource = gest.getDoctores().Tables[0].DefaultView;
            
        }

        private void btAgregar_Click(object sender, RoutedEventArgs e)
        {
            
            if (txtRut.Text == "")
            {
                
                MessageBox.Show("Falta Rut");

            }else if(txtNombre.Text=="") {
                MessageBox.Show("Falta nombre");

            }else if(txtEspecialidad.Text==""){
                MessageBox.Show("Falta Especialidad");
            }
            else {

                string rut = txtRut.Text.ToUpper();
                string nombre = txtNombre.Text.ToUpper();
                string especialidad = txtEspecialidad.Text.ToUpper();

                string result = gest.insertarDoctor(rut, nombre, especialidad);
                MessageBox.Show(result);
                txtRut.Text = "";
                txtNombre.Text = "";
                txtEspecialidad.Text = "";
                grillaDoctores.ItemsSource = gest.getDoctores().Tables[0].DefaultView;              
                txtRut.Focus();
            }
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btMinimizar_Click(object sender, RoutedEventArgs e)
        {
            
            this.WindowState = WindowState.Minimized;
        }

        private void progressBar1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
           
            
        }

        private void eventoRut(object sender, TextChangedEventArgs e)
        {
            grillaDoctores.ItemsSource= gest.getDoctoreslike2(txtBuscar.Text.ToUpper()).Tables[0].DefaultView;
           
           
        }
    }
}
